<?php

Yii::import('common.models.ad.*');

class Ad extends CWidget {

    public $position = 'right';
    public $limit = 2;
    public $order = 'random';
    public $divWrapperClass = '';

    public function run() {
	if ($this->order == 'random') {
	    $order = 'RAND()';
	} else {
	    $order = 'orders ' . $this->order;
	}

	//load ad models
	$models = AdBlock::model()->findAll(array(
	    'condition' => 'position = :position',
	    'limit' => $this->limit,
	    'order' => $order,
	    'params' => array(
		':position' => $this->position
	    )
	));

	$this->render($this->position, array(
	    'models' => $models
	));
    }

}

